package com.doit.day03

object _05_排序算子 {
  def main(args: Array[String]): Unit = {
    val list: List[Int] = List(5, 3, 4, 2, 1, 7, 6, 8)
    val sorted: List[Int] = list.sorted
    println(sorted)

    val perses: List[Pers] = List(
      new Pers("zss", 19, "male"),
      new Pers("lss", 19, "female"),
      new Pers("wws", 30, "female"),
      new Pers("aas", 19, "female"),
      new Pers("bbs", 26, "male"),
      new Pers("ccs", 26, "female")
    )
    /*perses.sorted(new Ordering[Pers] {
      override def compare(x: Pers, y: Pers) =x.id - y.id
    })*/

//    val perses1: List[Pers] = perses.sortBy(per => per.name)

    //我现在啊想按照id的值先进行比较，如果id的值相同id的升序，那么我就再去比较name的值 name的降序
/*    val res: List[Pers] = perses.sorted(new Ordering[Pers] {
      override def compare(x: Pers, y: Pers) = {
        //先比较id，在比较name
        if (x.id > y.id) {
          x.id - y.id
        } else if (x.id < y.id) {
          x.id - y.id
        } else {
          -x.name.compareTo(y.name)
        }
      }
    })*/

/*    val res: List[Pers] = perses.sortBy(tp => {
      //先比较id，在比较name
    })*/

    val res: List[Pers] = perses.sortWith((p1, p2) => {
      //id的升序，name的降序
      p1.name.compareTo(p2.name) > 0
    })


    res.foreach(println)

  }
}
